package Demo2;

public class Book {
    //成员变量
    private String name;//书名
    private String auther;//作者
    private String type;//类型
    private double cost;//价格
    public boolean borrowed;//是否借出

    //四个参数的构造方法
    public Book(String name, String auther, String type, double cost) {
        this.name = name;
        this.auther = auther;
        this.type = type;
        this.cost = cost;
    }

    //set方法
    public void setName(String name) {this.name = name;}//设置书名

    public void setAuther(String auther) {this.auther = auther;}//编辑作者名

    public void setType(String type) {this.type = type;}//设置类型

    public void setCost(int cost) {this.cost = cost;}//价格

    //get方法

    public String getName() {return name;}

    public String getAuther() {return auther;}

    public String getType() {return type;}

    public double getCost() {return cost;}

    //重写toString方法：系统默认生成后根据需要修改，以下修改了borrowed的表达
    //使用三目操作符，表达式结果是：“已借出”和“未借出”两种结果
    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", auther='" + auther + '\'' +
                ", type='" + type + '\'' +
                ", cost=" + cost +
                ", borrowed=" + ((this.borrowed == true) ? "已借出" : "未借出")  +
                '}';
    }
}
